/**
 * listener for save
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.JOptionPane;


/**
 * @author Master
 * @version $Revision: 1.0 $
 */
public class SaveListener implements ActionListener{

	/**
	 * Field SHI.
	 * (value is 10)
	 */
	private static final int SHI = 10;

	/**
	 * Method toString.
	
	 * @return String */
	@Override
	public String toString() {
		return "SaveListener []";
	}

	/**
	 * Method actionPerformed.
	 * @param e ActionEvent
	
	 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		try {
			final File file=new File("save.txt");
			file.createNewFile();
			final PrintWriter out = new PrintWriter(new FileWriter(file));
			out.println(GameInfo.getName());
			out.println(GameInfo.getDifficulty());
			out.println(GameInfo.getFighterSP());
			out.println(GameInfo.getPilotSP());
			out.println(GameInfo.getTraderSP());
			out.println(GameInfo.getEngineerSP());
			out.println(PlayerInfo.getMoney());
			out.println(PlayerInfo.getFuel());
			out.println(PlayerInfo.getCurrentSolarSystem().getName());
			out.println(PlayerInfo.getCurrentPlanet().getName());
			for (int i=0;i < SHI;i++) out.println(PlayerInfo.getStock(i));
			out.close();
		} catch (IOException e1) {
			JOptionPane.showMessageDialog( 
					ConfigurationScreen.MyFrame, "Unable to Save the file!");
		}
		
	}

}
